package com.deluxelx.soul.inn.web.chat;

import cn.hutool.core.collection.CollectionUtil;
import com.deluxelx.soul.inn.bean.chat.ChatRecordsParam;
import com.deluxelx.soul.inn.bean.chat.ChatRecordsVO;
import com.deluxelx.soul.inn.bean.chat.ChatRoomVO;
import com.deluxelx.soul.inn.common.result.SoulInnResult;
import com.deluxelx.soul.inn.service.chat.ChatService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 聊天、咨询-Controller
 *
 * @author liaozihao
 * @date 2024-04-26 9:58
 */
@RestController
@RequestMapping("/soul/inn/chat")
public class ChatController {

    @Resource
    private ChatService chatService;

    @GetMapping("/chatRoomList")
    public SoulInnResult<List<ChatRoomVO>> fetchChatRoomList(String userId) {
        List<ChatRoomVO> chatRoomVOS = chatService.fetchChatRoomList(userId);
        if (CollectionUtil.isNotEmpty(chatRoomVOS)) {
            return SoulInnResult.success(chatRoomVOS);
        }
        return SoulInnResult.fail("获取聊天室列表失败");
    }

    @PostMapping("/chatRecords")
    public SoulInnResult<ChatRecordsVO> fetchChatRecords(@RequestBody ChatRecordsParam param) {
        ChatRecordsVO chatRecords = chatService.fetchChatRecords(param);
        if (null != chatRecords) {
            return SoulInnResult.success(chatRecords);
        }
        return SoulInnResult.fail("获取聊天记录失败");
    }

}
